package com.mall.dubbo.api;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.UmsResourceMapper;
import com.mall.model.domain.UmsResource;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【ums_resource(后台资源表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService

public class UmsResourceApiImpl extends ServiceImpl<UmsResourceMapper, UmsResource>
        implements UmsResourceApi {

    @Autowired
    private UmsResourceMapper umsResourceMapper;


    @Override
    public Page<UmsResource> listPage(Integer categoryId, String nameKeyword, Integer pageNum, Integer pageSize, String urlKeyword) {

        Page<UmsResource> pageInfo = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<UmsResource> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(categoryId != null, UmsResource::getCategoryId, categoryId);
        queryWrapper.like(StringUtils.isNotEmpty(nameKeyword), UmsResource::getName, nameKeyword);
        queryWrapper.like(StringUtils.isNotEmpty(urlKeyword), UmsResource::getUrl, urlKeyword);
        return umsResourceMapper.selectPage(pageInfo, queryWrapper);
    }


    @Override
    public List<UmsResource> listResource(List<Long> resourceIds) {

        LambdaQueryWrapper<UmsResource> lqw = new LambdaQueryWrapper<>();
        lqw.in(CollUtil.isNotEmpty(resourceIds), UmsResource::getId, resourceIds);

        return umsResourceMapper.selectList(lqw);

    }

}




